﻿using System;
using System.Windows.Forms;
using System.Drawing;
using Server;

namespace ServerUI
{
    public partial class ServerUI : Form
    {

        Color running = Color.GreenYellow;
        Color stopped = Color.Red;
        string runningMsg = "Running";
        string stoppedMsg = "Stopped";
        bool ServerState = false;
        RemoteServer remoteServer;

        public ServerUI()
        {
            InitializeComponent();
            ServerState = false;
            StatusMsg.Text = stoppedMsg;
            StatusIndicator.BackColor = stopped;
            State.Text = stoppedMsg;

            remoteServer = new RemoteServer(); // take the default port
        }

        private void StateButton_Click(object sender, EventArgs e)
        {
            ServerState = remoteServer.Running;
            
            if (ServerState)
            {
                ServerState = false;
                remoteServer.Stop();
                Stop();
            }
            else
            {
                ServerState = true;
                remoteServer.Start();
                Start();
            }
        }

        private void Start()
        {
            StatusIndicator.BackColor = running;
            StatusMsg.Text = runningMsg;
            State.Text = runningMsg;
        }

        private void Stop()
        {
            StatusIndicator.BackColor = stopped;
            StatusMsg.Text = stoppedMsg;
            State.Text = stoppedMsg;
        }
    }
}
